package top.lshaci.learning.springboot.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * RequestController
 *
 * @author lshaci
 * @since 1.0.0
 */
@Controller
public class RequestController {

    @GetMapping("/goto")
    public String gotoPage(HttpServletRequest request) {
        request.setAttribute("reqMsg", "req_msg");
        return "forward:success";
    }

    @ResponseBody
    @GetMapping("/success")
    public Object success(@RequestAttribute String reqMsg,
                          HttpServletRequest request
    ) {
        Map<String, Object> map = new HashMap<>();
        map.put("reqMsg_annotation", reqMsg);
        map.put("reqMsg_req", request.getAttribute("reqMsg"));
        return map;
    }
}
